package demo1;

class Solution {
    public ListNode deleteDuplicates(ListNode head) {
         ListNode newHead = new ListNode() ;
         ListNode newEnd = newHead ;
         ListNode cur = head ;

         while(cur!=null){
           if(cur.next!=null && cur.val == cur.next.val){
                while(cur.next!=null &&cur.val==cur.next.val){
                    cur= cur.next ;
                }
                cur=cur.next ;
           }else{
               newEnd.next = cur ;
               newEnd = newEnd.next ;
               cur = cur.next ;
           }
         }
         
         newEnd.next = null ;

    return newHead.next ;


    }
}